<?php

namespace App\Adapters;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;


/**
 * 首页适配器
 * Class HomeAdapter
 * @package App\Adapters
 */
class SeminarAdapter
{
    /**
     * @var
     */
    protected $app;

    /**
     * @var array
     */
    protected $instance = [
        1   =>  'App\Services\SeminarTemplates\SeminarFontService',
    ];

    /**
     * 更具类型创建对应模块处理服务
     * HomeAdapter constructor.
     * @param int $type
     */
    public function __construct(int $type)
    {

        try{
            $instanceName = $this->instance[$type];
        }catch (\Exception $exception) {
            throw new NotFoundResourceException('不存在的模版类型');
        }

        if (class_exists($instanceName)) {
            $this->app = \App::make($instanceName);
        }
        else{
            throw new NotFoundHttpException('获取模板数据处理服务失败');
        }

        return $this;
    }


    /**
     * 处理该模块数据
     * @author Jerry
     * @param array $stencil
     * @return bool
     */
    public function handle($stencil = array())
    {
        if (get_class($this->app)) {
            return $this->app->handle($stencil);
        }

        return false;
    }
}